<template>
  <div>
    <el-dialog
      title="新建预约归还单"
      :visible.sync="visible"
      :modal-append-to-body="false"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      @close="closeDialog"
      
    >
      <div class="warn">
        <p>
          <strong>说明:</strong>
          <br />标记*的必须录入数据的字段
          <br />
        </p>
      </div>
      <div class="form"></div>
      <el-form
        ref="submit"
        :model="submit"
        label-position="left"
        label-width="105px"
        size="mini"
        inline
      >
        <el-form-item label="*预约归还日期" label-width="110px">
          <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="submit.date"
            value-format="yyyy-MM-dd"
            style="width: 100%;"
          ></el-date-picker>
        </el-form-item>&emsp;&emsp;
        <el-form-item label="*业务员" label-width="68px">
          <el-input v-model="submit.bizname" style="width:150px;"></el-input>
          <el-popover placement="right" width="300" v-model="UserListApp.visible">
            <div style="width:300px">
              <el-table
                border
                :data="Lists.userList"
                @row-click="selectUser"
                :stripe="true"
                :header-cell-style="{background:'#e3e5e9',color:'#606266'}"
                :row-style="{height:'5px'}"
                :cell-style="{padding:'5px 0'}"
                tooltip-effect="light"
                highlight-current-row
                style="width: 100%;"
                height="300px"
              >
                <el-table-column prop="name" label="姓名"></el-table-column>
              </el-table>
              <div style="width:100px;background:red;margin:3px auto;">
                <el-button type="primary" @click="SureSelectUser">确定选择业务员</el-button>
              </div>
            </div>
            <el-button slot="reference" @click="UserListApp.visible=true">选择</el-button>
          </el-popover>
        </el-form-item>
        <br />&emsp;
        <el-form-item label="备注" label-width="40px">
          <el-input v-model="submit.memo" style="width:700px;"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="visible = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="Submit()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    form: {
      style: Object
    },
    detail_list: {}
  },
  data() {
    return {
      selectUserList: [],
      submit: {
        id: "",
        statu: "",
        isappointment: "",
        appDate: "",
        borrowId: "",
        returnDate: "",
        borrowername: "",
        barrowerOrgname: "",
        bizname: "",
        returnRef: ""
      },
      visible: true,

      Lists: {
        orangeList: [],
        userList: []
      },
      UserListApp: {
        visible: false
      },
      App_Borrow_Detail_List: {
        list: [],
        SelectRow: {}
      },
      storeList: []
    };
  },
  methods: {
    Check() {
      if (
        this.submit.date == null ||
        this.submit.date == "" ||
        this.submit.bizname == null ||
        this.submit.bizname == ""
      ) {
        this.$message.error("请录入完整的数据！");
        return false;
      }
      return true;
    },
    Submit() {
      let f = JSON.parse(JSON.stringify(this.form));
      let submitForm = {
        statu: "申请归还中",
        isappointment: "是",
        appDate: f.date,
        borrowId: f.borrowref,
        borrowcode: "",
        returnDate: "/",
        borrowername: f.borrower,
        barrowerOrgname: f.orangename,
        bizname: f.bizname,
        returnRef: ""
      };

      this.$http
        .get("borrow/selectOne", {
          params: {
            id: submitForm.borrowId
          }
        })
        .then(response => {
          submitForm.borrowcode = response.data.ref;
          window.console.log("form", this.form);
          window.console.log("form", submitForm);
          var day = new Date();
          day.setTime(day.getTime());
          submitForm.returnRef =
            "RO" +
            day.getFullYear() +
            (day.getMonth() + 1) +
            day.getDate() +
            day.getHours() +
            day.getMinutes() +
            day.getSeconds();
          this.$http.post("assetReturn/insert", submitForm).then(response => {
            if (response.data == "success") {
              this.$message({
                message: "生成完成，请到资产归还界面查看",
                type: "success"
              });
              this.visible = false;
            }
          });
        });
      //   window.console.log(this.submit);
    },
    closeDialog() {
      window.console.log("dfialog-close");
      this.$emit("dialog-close");
    },
    NeedRefresh() {
      this.$emit("refresh");
    },
    selectUser(Row) {
      this.submit.bizname = Row.name;
    },
    selectGood(Row) {
      this.miniApp_Good_List.SelectRow = JSON.parse(JSON.stringify(Row));
    },
    GetLists() {
      this.$http.get("/user/list").then(response => {
        this.Lists.userList = response.data;
      });
      this.$http
        .post("BorrowDetailDetail/somelist", { borrowref: this.submit.id })
        .then(response => {
          this.App_Borrow_Detail_List.list = response.data;
        });
    },
    SureSelectUser() {
      this.UserListApp.visible = false;
    }
  },
  created() {
    this.submit = JSON.parse(JSON.stringify(this.form));
    this.submit.ref = "";
    this.submit.bizname = "";
    this.submit.borrowref = this.form.id;
    this.GetLists();
  }
};
</script>

<style>
.form {
  margin-top: 20px;
}
</style>